package com.gym.code.generator.utils;

import org.apache.commons.lang.StringUtils;

/**
 * 
 * @author xinchun.wang 
   @email: 532002108@qq.com
 * @createTime 2015-4-13 下午9:20:13
 */
public class LocalStringUtils {
	public static String toFirstLetterUpper(String source) {
		if (StringUtils.isEmpty(source)) {
			return "";
		}
		return source.substring(0, 1).toUpperCase() + source.substring(1);
	}
	
	public static String toFirstLetterLower(String source) {
		if (StringUtils.isEmpty(source)) {
			return "";
		}
		return source.substring(0, 1).toLowerCase() + source.substring(1);
	}
	
	
	public static String removeLastChar(String source,char c) {
		if (StringUtils.isEmpty(source)) {
			return "";
		}
		if(source.toCharArray()[source.length() -1] == c){
			return source.substring(0,source.length()-1);
		}
		return source;
	}
	
	
	/**
	 * 转换名称
	 * @param dbObjName
	 * @return
	 */
	public static String toBeanName(String source, boolean firstUpper) {
		// 小写
		String name = source.toLowerCase();
		// 分割"_"
		String[] strs = name.split("_");
		name = ((firstUpper ? strs[0].substring(0,1).toUpperCase() : strs[0].substring(0,1).toLowerCase()) + strs[0].substring(1));
		if (strs.length > 1) {
			for (int i = 1; i < strs.length; i++) {
				// 首字母大写
				name += (strs[i].substring(0,1).toUpperCase() + strs[i].substring(1));
			}
		}
		return name;
	}
	

}
